package com.gzs.zhdj.mapper;

import com.github.pagehelper.Page;
import com.gzs.zhdj.domain.dto.ActPageDto;
import com.gzs.zhdj.domain.dto.ActivitiesDto;
import com.gzs.zhdj.domain.dto.ParticipantDto;
import com.gzs.zhdj.domain.entity.Activities;
import com.gzs.zhdj.domain.entity.PartyMember;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;


@Mapper
public interface ActivityMapper {

    @Insert("insert into party_activities(name, activity_startdate, activity_enddate, location, activity_type, description, org_name) values (#{name},#{activityStartdate},#{activityEnddate},#{location},#{activityType},#{description},#{orgName})")
    void createAct(ActivitiesDto act);

    @Select("select * from party_activities where name = #{name}")
    int getaIdByName(String name);

    @Insert("insert into participants(p_id, a_id) values (#{pId},#{aId})")
    void joinAct(@Param("pId") int pId, @Param("aId") int aId);

    Page<Activities> pageQuery(@Param("name") String name, @Param("start") LocalDateTime start, @Param("end") LocalDateTime end);

    @Update("update participants set feel = #{filePath} where p_id = #{pId} and a_id = #{aId}")
    void uploadFeel(@Param("pId") int pId, @Param("aId") int aId, @Param("filePath") String filePath);

    @Select("select * from participants where a_id = #{id}")
    List<ParticipantDto> getFeel(int id);

    @Select("select * from participants where p_id = #{pId} and a_id = #{aId}")
    List<ParticipantDto> getSelfFeel(ParticipantDto participantDto);

    @Delete("delete from party_activities where id = #{id}")
    void deleteAct(int id);

    @Select("select * from party_activities where id = #{id}")
    ActivitiesDto getActById(int id);


    void updateAct(ActivitiesDto act);

    @Select("select * from participants where p_id = #{pId} and a_id = #{aId}")
    ParticipantDto getTwoId(@Param("pId") int pId, @Param("aId") int aId);


    Page<Activities> pageQueryById(@Param("pId") int pId, @Param("name") String name, @Param("start") LocalDateTime start, @Param("end") LocalDateTime end);

    @Update("UPDATE party_activities SET member_count = member_count + 1 WHERE id = #{aId}")
    void countAdd(int aId);

    @Update("UPDATE party_activities SET member_count = member_count - 1 WHERE id = #{aId}")
    void countCut(int aId);

    @Delete("delete from participants where p_id = #{pId} and a_id = #{aId}")
    void cancelAct(@Param("pId") int pId, @Param("aId") int aId);
}
